﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SdmxMl.Manager;
using SdmxMl.Structure;
using SdmxMl.Common;
namespace bfs.sms.sdmx.util.Variable
{
    public class Variable
    {
        public CodeListType Codelist { get; set; }
        public CodeListType Qualitylist { get; set; }
        public ConceptType Concept { get; private set; }
        public TextFormatType FormatType { get; set; }
        /// <summary> To identify excel worksheet </summary>
        public string CodeSheetId { get; set; }

        public Variable(ConceptType concept, CodeListType clt)
        {
            Concept = concept;
            Codelist = clt;
            FormatType = concept.TextFormat;
            CodeSheetId = clt != null ? clt.Id : string.Empty;
        }

        /// <summary> Provides codelist to operate in column. </summary>
        /// <remarks> Can be a codelist composed from main and secondary</remarks>
        /// <returns>the codelist to associate to the column</returns>
        public CodeListType GetCodelistAndQuality()
        {
            CodeListType clt = Codelist;

            // Do we need to merge codes ?
            if (Qualitylist != null && Codelist != null)
            {
                clt = new CodeListType();
                clt.Id = Codelist.Id;
                clt.AgencyId = Codelist.AgencyId;
                clt.Version = Codelist.Version;
                clt.Name = Codelist.Name;
                clt.Description = Codelist.Description;

                // Merge codes of the two codelists
                clt.CodeList.AddRange(Codelist.CodeList.ToArray());
                clt.CodeList.AddRange(Qualitylist.CodeList.ToArray());
            }

            return clt;
        }
  

    }
}
